package com.zrrd.product.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.zrrd.common.result.Result;
import com.zrrd.model.product.BaseTrademark;
import com.zrrd.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService trademarkService;

    @GetMapping("/{page}/{limit}")
    public Result<Page> list(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit) {
        Page<BaseTrademark> pageInfo = new Page<>(page, limit);
        trademarkService.page(pageInfo, null);

        return Result.ok(pageInfo);
    }

    @PostMapping("/save")
    public Result<String> add(@RequestBody BaseTrademark baseTrademark) {
        boolean save = trademarkService.save(baseTrademark);
        if (save) {
            return Result.ok("提交成功");
        }
        {
            return Result.fail("添加失败");
        }

    }

    //查询全部品牌列表
    @GetMapping("/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkLIst() {
        return Result.ok(trademarkService.list(null));
    }

    //修改品牌
    @PutMapping("/update")
    public Result<String> update(@RequestBody BaseTrademark trademark) {
        boolean update = trademarkService.updateById(trademark);
        if (update) {
            return Result.ok("修改成功");
        } else {
            return Result.fail("修改失败");
        }
    }

    //删除品牌
    @DeleteMapping("/remove/{id}")
    public Result<String> removeById(@PathVariable("id") Long id) {
        boolean remove = trademarkService.removeById(id);
        if (remove) {
            return Result.ok("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }
}
